<?php
/* @var $this ProductController */

$this->breadcrumbs=array(
  Yii::t('default', 'Products') => array('index'),
  Category::model()->getName($product->categoryID) => array('index', 'catID' => md5($product->categoryID)),
  Yii::t('default', 'Product Detail')
);
?>
<h2 class="filtering">
  <span> <?php echo Yii::t('default', 'Products')?> </span>
</h2>
<!-- **Primary Section** -->
<section id="primary" class="content-full-width"> 

  <!-- **Product** -->
  <div class="product">
      <div class="images">
          <a class="woocommerce-main-image" title="">
            <?php
              $image = Product::model()->getProductFile($product->id, 520, 400); 
            ?>
            <img src="<?php echo Yii::app()->baseUrl ?>/upload/product/thumbs_520x400/<?php echo $image?>" class="thumbs04" alt="" title=""> 
          </a>
          <?php
            $product_files = Product::model()->getProductFiles($product->id, $image);
            if (!empty($product_files)) {
          ?>
          <div class="thumbnails"> 
            <div id="product-thumbnails">
              <?php foreach ($product_files as $product_file) {
                if ($product_file['save'] == $image)
                  continue;
              ?>
                <a title="" class="product_thumbnail"> <img class="thumbs02" src="<?php echo Yii::app()->baseUrl ?>/upload/product/thumbs_125x120/<?php echo $product_file['save']?>" alt="" title=""> </a>
              <?php }?>
            </div>
            
            <div class="product-arrows">
              <a href="#" title="" class="prev" id="product-thumbnails-prev"> </a>
              <a href="#" title="" class="next" id="product-thumbnails-next"> </a>
            </div>
          </div>
          <?php }?>
        </div>
        <div class="summary">
          <h2> <?php echo $product->name?> </h2>
            <?php if ($product->price != '') {?>
            <p class="price"><i class="icon-tag"></i> <?php echo ($product->price == '') ? Yii::t('default', 'Updating') . '...' : $product->price?> </p>
            <?php }?>
            <div class="description">
              <?php echo $product->detail?>
                <p> <strong> <?php echo Yii::t('default', 'Category')?> </strong> : <?php echo $category?> </p>
                <p> <strong> <?php echo Yii::t('default', 'Price')?> </strong> : <?php echo ($product->price == '') ? Yii::t('default', 'Updating') . '...' : $product->price?> </p>
            </div>
        </div>
        
        <?php if (!empty($related_products)) {?>
          <div class="border-title"> 
            <h2> <?php echo Yii::t('default', 'Related Products')?> </h2> 
          </div>
          
          <!-- **Product Carousel Wrapper** -->
          <div class="product-carousel-wrapper gallery">
            <ul class="product-carousel products product-list">
              <?php foreach ($related_products as $related_product) {
                $img = Product::model()->getProductFile($related_product['id'], 250, 240);
              ?>
                <li>
                  <div class="product-thumb">
                    <a href="" title=""> 
                      <?php echo CHtml::image(Yii::app()->baseUrl . "/upload/product/thumbs_250x240/$img", "image", array('class'=>'thumbs03'));?> 
                    </a>
                    <div class="product-overlay">
                      <a class="link" title="<?php echo $related_product['name']?>" href="<?php echo Yii::app()->baseUrl?>/product/detail/id/<?php echo md5($related_product['id'])?>">
                        <span class="icon-external-link"> </span>
                      </a>
                    </div>
                  </div>
                  <h4><?php echo $related_product['name']?></h4>
                  <p><?php echo $related_product['description']?></p>
                </li>
              <?php }?>
            </ul>
            <div class="carousel-arrows">
              <a href="#" title="" class="product-prev-arrow"> <span
                class="icon-chevron-left"> </span> </a> <a href="#" title=""
                class="product-next-arrow"> <span class="icon-chevron-right"> </span>
              </a>
            </div>
          </div>
          <!-- **Product Carousel Wrapper - End** -->
        <?php }?>

</div>
</section><!-- **Primary Section** -->

<script type="text/javascript">
$(function () {
  $(".product_thumbnail").click(function() {
    var thumbnail = $(this).children('img').attr('src');
    var file1 = thumbnail.substr(thumbnail.lastIndexOf("/") + 1);
    var image = $(".woocommerce-main-image img").attr('src');
    var file2 = image.substr(image.lastIndexOf("/") + 1);
    $(".woocommerce-main-image img").attr('src' , baseUrl + '/upload/product/thumbs_520x400/' + file1);
    $(this).children('img').attr('src', baseUrl + '/upload/product/thumbs_125x120/' + file2);
  });
});
</script>